package com.dimanche.library_db.dao;

import androidx.lifecycle.LiveData;
import androidx.room.Dao;
import androidx.room.Delete;
import androidx.room.Insert;
import androidx.room.OnConflictStrategy;
import androidx.room.Query;
import androidx.room.Update;

import com.dimanche.library_db.entity.WordEntity;

import java.util.List;

import io.reactivex.Observable;

/**
 * author : Dimanche
 * date   : 2021/3/22 11:08
 * desc   :字典Dao
 * version: 1.0
 */
@Dao
public interface DirDao {
    //====================插入操作,若存在相同的主键数据则直接覆盖=====================

    @Insert(onConflict = OnConflictStrategy.REPLACE)
    Long insert(WordEntity t);

    @Insert(onConflict = OnConflictStrategy.REPLACE)
    List<Long> insert(WordEntity... ts);

    @Insert(onConflict = OnConflictStrategy.REPLACE)
    List<Long> insert(List<WordEntity> tList);

    //==============================删========================================
    @Delete
    int delete(WordEntity t);

    @Delete
    int delete(WordEntity... ts);

    /**
     * 根据名字删除
     *
     * @param word
     * @return
     */
    @Query("delete from Word where word=:word")
    int deleteByName(String word);

    /**
     * 删除所有数据
     *
     * @return
     */
    @Query("delete from Word")
    int deleteAll();


    //==============================更新======================================
    @Update
    int update(WordEntity t);

    @Update
    int update(WordEntity... ts);

    //==============================查询=====================================

    @Query("select * from Word")
    LiveData<List<WordEntity>> queryAll();

    @Query("select * from Word where Word.id=:id")
    LiveData<WordEntity> queryById(int id);

    @Query("select * from Word where Word.word=:word")
    LiveData<List<WordEntity>> queryByWord(String word);


}
